<template>
    <div class="mine">
        <div class="mineTop">
            Của tôi
        </div>
        <div class="mineContentWapper">
            <div class="content">

                <div class="touxiangAndPhoneNum">
                    <img src="@/assets/touxiang.png" alt="">
                    <p class="phoneNum">{{ phoneNum ? formatString(phoneNum) : '' }}</p>
                </div>
                <div class="menu">
                    <div class="menuItem" @click="toOrderReserva">
                        <div class="leftIconAndName">
                            <img src="@/assets/reservaIcon.png" alt="">
                            <p>Đơn hẹn</p>
                        </div>
                        <img src="@/assets/jiantou_right.png" alt="">
                    </div>
                    <div class="menuItem" @click="logoutClick">
                        <div class="leftIconAndName">
                            <img src="@/assets/logout.png" alt="">
                            <p>Đăng xuất</p>
                        </div>
                        <img src="@/assets/jiantou_right.png" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang='ts'>
import api from '@/api';
import { getItem, removeItem } from '@/utils/token-utils';
import { formatString } from '@/utils/toolsUtils';
import { Toast } from 'tdesign-mobile-vue';
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter()

let phoneNum = ref(getItem('cellular'))

const logoutClick = async () => {
    try {
        let logoutRes = (await api.logout({
            uuid: getItem('uuid'),
            token: getItem('token')
        })).data
        if (logoutRes.code == 0) {
            removeItem('uuid')
            removeItem('token')
            removeItem('cellular')
            Toast({
                message: logoutRes.message,
                duration: 3 * 1000
            })
            router.replace({
                path: '/'
            })
        } else {
            Toast({
                message: logoutRes.message,
                duration: 3 * 1000
            })
        }
    } catch (error) {
        console.log(error);

    }
}

const toOrderReserva = async () => {
    router.push({
        path:'/orderReserva'
    })
}
</script>

<style scoped>
.mine {
    height: 100%;
    background-color: #009959;


    .mineTop {
        width: 100%;
        min-height: 2.3rem;
        display: flex;
        justify-content: center;
        align-items: center;

        /* font-family: SF Pro, SF Pro; */
        font-weight: 600;
        font-size: 18px;
        color: #FFFFFF;
        line-height: 26px;
        text-align: center;
        font-style: normal;
        text-transform: none;

    }

    .mineContentWapper {
        width: 100%;
        height: calc(100% - 2.3rem);
        display: flex;
        flex-direction: column;
        justify-content: flex-end;

        .content {
            width: 100%;
            height: 85%;
            background-color: #F7F7FA;
            border-radius: 12px 12px 0px 0px;
            position: relative;
            padding: 0 .8rem;
            /* overflow: hidden; */

            .touxiangAndPhoneNum {
                width: 100%;
                position: absolute;
                top: -2rem;
                left: 0;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;

                &>img {
                    display: block;
                    width: 3.7rem;
                    height: 3.7rem;
                }

                .phoneNum {
                    font-family: SF Pro, SF Pro;
                    font-weight: 600;
                    font-size: 1rem;
                    color: #292B33;
                    line-height: 1.5rem;
                    text-align: left;
                    font-style: normal;
                    text-transform: none;
                }
            }


            .menu {
                /* padding: .8rem; */
                background-color: #fff;
                margin-top: 4rem;
                border-radius: .2rem;

                .menuItem {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    padding: .8rem;

                    .leftIconAndName {
                        display: flex;
                        justify-content: flex-start;
                        align-items: center;

                        &>img {
                            display: block;
                            width: 1.4rem;
                            height: 1.4rem;
                            margin-right: .4rem;
                        }

                        &>p {
                            font-family: SF Pro, SF Pro;
                            font-weight: 600;
                            font-size: .7rem;
                            color: #292B33;
                            line-height: 1.1rem;
                            text-align: left;
                            font-style: normal;
                            text-transform: none;
                        }
                    }

                    &>img {
                        display: block;
                        width: .8rem;
                        height: .8rem;
                    }
                }
            }
        }
    }
}
</style>